extends Node2D

@onready var bgm = $bgm
@onready var me = $me
@onready var se = $se
@onready var animation_player = $transition/AnimationPlayer
@onready var trans_sprite = $transition/Sprite2D

const STATE_ACTIVE = "active"
const STATE_FADEIN = "fadein"
const STATE_FADEOUT = "fadeout"
const STATE_DEAD = "dead"

var show_trans_flag = false

var player

func show_trans(id):
	if animation_player.is_playing(): return
	trans_sprite.texture = load("res://assets/ui/过场图%d.png" % id)
	trans_sprite.show()
	show_trans_flag = true
	animation_player.play("fadein")

func game_over():
	get_tree().quit()

func play_se(_name):
	se.stop()
	match(_name):
		"shoot":
			se.stream = load("res://assets/audio/Shot1.wav")
	se.play()


func play_me(_name):
	me.stop()
	match(_name):
		"get_item":
			me.stream = load("res://assets/audio/Chime2.wav")
		"hit":
			me.stream = load("res://assets/audio/Damage1.wav")
		"explosion":
			me.stream = load("res://assets/audio/Explosion1.wav")
		"level_up":
			me.stream = load("res://assets/audio/Heal3.wav")	
	me.play()		




func _on_animation_player_animation_finished(anim_name):
	if show_trans_flag:
		show_trans_flag = false
		await get_tree().create_timer(1.5).timeout
		animation_player.play_backwards("fadein")
